<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<%@ include file = "lianjie.jsp" %>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
	<%
		request.setCharacterEncoding("UTF-8");
		String add_ISBN = request.getParameter("ISBN");
		String add_Sname = request.getParameter("Sname");
		String add_author = request.getParameter("author");
		String add_type = request.getParameter("type");
		String add_press = request.getParameter("press");
		String add_price = request.getParameter("price");
		String add_surplus = request.getParameter("surplus");
		int resultNum = 0;
		String sql = "select * from booksmassage where ISBN='" + add_ISBN + "'";
		ResultSet rs1 = stmt.executeQuery(sql);
		if(rs1.next()){
			out.println("该书已存在");
			response.setHeader("Refresh", "1;URL=add_student.jsp");
		}else if(add_ISBN == ""){
			out.println("ISBN不能为空！");
			response.setHeader("Refresh", "1;URL=add_student.jsp");
		}else if(add_Sname == ""){
			out.println("书名不能为空！");
			response.setHeader("Refresh", "1;URL=add_student.jsp");
		}else if(add_author == ""){
			out.println("作者不能为空!");
			response.setHeader("Refresh", "1;URL=add_student.jsp");
		}else if(add_type == ""){
			out.println("类型不能为空!");
			response.setHeader("Refresh", "1;URL=add_student.jsp");
		}else if(add_press == ""){
			out.println("出版社不能为空!");
			response.setHeader("Refresh", "1;URL=add_student.jsp");
		}else if(add_price == ""){
			out.println("价钱不能为空!");
			response.setHeader("Refresh", "1;URL=add_student.jsp");
		}else if(add_surplus == ""){
			out.println("数目不能为空!");
			response.setHeader("Refresh", "1;URL=add_student.jsp");
		}else{
			String insert_sql = "insert into booksmassage(ISBN,name,author,type,press,price,surplus,loan) values('"
					+ add_ISBN + "','" + add_Sname + "','"+add_author + "','" + add_type + "','" + add_press + "'," + add_price + ","+add_surplus+",0);";
			
					
			try {
				stmt.executeUpdate(insert_sql);
			} catch (SQLException e) {
				out.println("错误提示：" + e.getMessage());
			} finally {
				stmt.close();
				conn.close();
			}
			out.println("添加成功");
			response.setHeader("Refresh", "1;URL=teacher.jsp");
		}
	%>
</body>
</html>